package cn.iocoder.yudao.module.biz.service.emergencyRanks;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyRanks.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyRanks.BizEmergencyRanksDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.biz.convert.emergencyRanks.BizEmergencyRanksConvert;
import cn.iocoder.yudao.module.biz.dal.mysql.emergencyRanks.BizEmergencyRanksMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 应急队伍 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BizEmergencyRanksServiceImpl implements BizEmergencyRanksService {

    @Resource
    private BizEmergencyRanksMapper emergencyRanksMapper;

    @Override
    public String createEmergencyRanks(BizEmergencyRanksCreateReqVO createReqVO) {
        // 插入
        BizEmergencyRanksDO emergencyRanks = BizEmergencyRanksConvert.INSTANCE.convert(createReqVO);
        emergencyRanksMapper.insert(emergencyRanks);
        // 返回
        return emergencyRanks.getId();
    }

    @Override
    public void updateEmergencyRanks(BizEmergencyRanksUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateEmergencyRanksExists(updateReqVO.getId());
        // 更新
        BizEmergencyRanksDO updateObj = BizEmergencyRanksConvert.INSTANCE.convert(updateReqVO);
        emergencyRanksMapper.updateById(updateObj);
    }

    @Override
    public void deleteEmergencyRanks(String id) {
        // 校验存在
        this.validateEmergencyRanksExists(id);
        // 删除
        emergencyRanksMapper.deleteById(id);
    }

    private void validateEmergencyRanksExists(String id) {
        if (emergencyRanksMapper.selectById(id) == null) {
            throw exception(EMERGENCY_RANKS_NOT_EXISTS);
        }
    }

    @Override
    public BizEmergencyRanksDO getEmergencyRanks(String id) {
        return emergencyRanksMapper.selectById(id);
    }

    @Override
    public List<BizEmergencyRanksDO> getEmergencyRanksList(Collection<String> ids) {
        return emergencyRanksMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<BizEmergencyRanksDO> getEmergencyRanksPage(BizEmergencyRanksPageReqVO pageReqVO) {
        return emergencyRanksMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizEmergencyRanksDO> getEmergencyRanksList(BizEmergencyRanksExportReqVO exportReqVO) {
        return emergencyRanksMapper.selectList(exportReqVO);
    }

}
